﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace _1.OrderService
{
    public partial class ExportOrImportForm : Form
    {
        Form1 _form1;
        OrderService _orderService;
        public ExportOrImportForm(Form1 form1,OrderService orderService)
        {
            InitializeComponent();
            _form1 = form1;
            _orderService = orderService;
        }

        private void button_quit_Click(object sender, EventArgs e)
        {
            _form1.Show();
            this.Close();
        }

        private void button_export_Click(object sender, EventArgs e)
        {
            string fileName = textBox_export.Text + ".xml";
            _orderService.Export(fileName);
            DialogResult dr = MessageBox.Show(String.Format("导出到{0}成功", fileName), "提示", MessageBoxButtons.OK);
        }

        private void button_import_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.InitialDirectory = Application.StartupPath;

            ofd.Title = "请选择要打开的文件";

            ofd.Multiselect = false;

            ofd.Filter = "xml|*.xml";

            //ofd.FilterIndex = 2;

            ofd.RestoreDirectory = true;
            if (ofd.ShowDialog() == DialogResult.OK)
            {

                string filePath = ofd.FileName;
                string fileName = ofd.SafeFileName;
                _orderService.Import(fileName);
                DialogResult dr = MessageBox.Show(String.Format("从{0}导入订单成功", fileName), "提示", MessageBoxButtons.OK);
            }

        }
    }
}
